<?php
namespace app\home\controller;
header("Content-type: text/html; charset=utf-8");
use app\admin\model\Account;
use app\admin\model\TeacherWithdrawals;
use app\admin\model\Order;
use app\admin\model\Lesson;
use think\Cache;
use think\Controller;
use think\Db;
use think\Validate;
use app\admin\model\User;
class Teacher extends Controller {
    public function rec_teacher(){
        $id = $_POST['id'];
        $info =Db::name('user')->where(array('rec_id'=>$id,'user_auth'=>2))->order('id desc')->select();
        return json($info);
    }
    public function rec_student(){
        $id = $_POST['id'];
        $info =Db::name('user')->where(array('rec_id'=>$id,'user_auth'=>3))->order('id desc')->select();
        return json($info);
    }
    public function rec_classroom(){
        $id = $_POST['id'];
        $info =Db::name('classroom')
            ->where(array('rec_classroom_user'=>$id))
            ->join('book_user','classroom_owner=book_user.id','LEFT')
            ->order('book_classroom.id desc')
            ->field('book_classroom.classroom_sn,book_classroom.classroom_address,book_user.full_name')
            ->select();
        return json($info);
    }
    public function classroom(){
        $id = $_POST['id'];
        $info =Db::name('classroom')
            ->where(array('classroom_owner'=>$id))
            ->join('book_user','classroom_owner=book_user.id','LEFT')
            ->order('book_classroom.id desc')
            ->field('book_classroom.classroom_sn,book_classroom.classroom_address,book_classroom.classroom_owner,book_user.full_name')
            ->select();
        return json($info);
    }
    public function my_lesson_all(){
        //$_POST['id']=2;
        $id = $_POST['id'];
        $info =Db::name('lesson')
            ->where(array('teacher_id'=>$id))
            ->join(' book_subject ','subject_id=book_subject.id','LEFT')
            ->join(' book_lesson_program ','program_id=book_lesson_program.id','LEFT')
            ->join(' book_service_target ','service_target_id=book_service_target.id','LEFT')
            ->join(' book_lesson_nature ','lesson_nature_id=book_lesson_nature.id','LEFT')
            ->join(' book_user ','teacher_id=book_user.id','LEFT')
            ->join(' book_classroom ','classroom_id=book_classroom.id','LEFT')
            ->join(' book_city ','book_lesson.city_id=book_city.id','LEFT')
            ->field('book_lesson.id,book_lesson.lesson_sn,book_subject.subject,book_lesson_program.program,book_service_target.service_target,book_lesson_nature.lesson_nature,book_user.full_name,book_user.sex,book_user.age,book_classroom.classroom_address,book_lesson.lesson_method,book_lesson.is_comment,book_lesson.lesson_cost,book_lesson.teacher_group_description,book_lesson.lesson_feature,book_lesson.cost_type,book_lesson.add_description,book_lesson.teacher_description,book_lesson.classroom_description,book_lesson.lesson_name,book_lesson.adapt_crowd,book_lesson.cost_type_description,book_lesson.lesson_time_description,book_lesson.teacher_group_images,book_lesson.lesson_num,book_city.city,book_lesson.is_approve,book_lesson.com_lesson_num')
            ->order('book_lesson.id desc')
            ->select();
        return json($info);
    }
    public function my_lesson_now(){
        //$_POST['id']=2;
        $id = $_POST['id'];
        $info =Db::name('lesson')
            ->where(array('teacher_id'=>$id,'is_approve'=>1))
            ->join(' book_subject ','subject_id=book_subject.id','LEFT')
            ->join(' book_lesson_program ','program_id=book_lesson_program.id','LEFT')
            ->join(' book_service_target ','service_target_id=book_service_target.id','LEFT')
            ->join(' book_lesson_nature ','lesson_nature_id=book_lesson_nature.id','LEFT')
            ->join(' book_user ','teacher_id=book_user.id','LEFT')
            ->join(' book_classroom ','classroom_id=book_classroom.id','LEFT')
            ->join(' book_city ','book_lesson.city_id=book_city.id','LEFT')
            ->field('book_lesson.id,book_lesson.lesson_sn,book_subject.subject,book_lesson_program.program,book_service_target.service_target,book_lesson_nature.lesson_nature,book_user.full_name,book_user.sex,book_user.age,book_classroom.classroom_address,book_lesson.lesson_method,book_lesson.is_comment,book_lesson.lesson_cost,book_lesson.teacher_group_description,book_lesson.lesson_feature,book_lesson.cost_type,book_lesson.add_description,book_lesson.teacher_description,book_lesson.classroom_description,book_lesson.lesson_name,book_lesson.adapt_crowd,book_lesson.cost_type_description,book_lesson.lesson_time_description,book_lesson.teacher_group_images,book_lesson.lesson_num,book_city.city,book_lesson.is_approve,book_lesson.com_lesson_num')
            ->order('book_lesson.id desc')
             ->select();
        return json($info);
    }
    public function my_lesson_details(){
        $id= $_POST['id'];
        $lessons = Db::name('lesson');
        $lesson = $lessons
            ->where(array('book_lesson.id' => $id))
            ->join(' book_subject ','subject_id=book_subject.id','LEFT')
            ->join(' book_lesson_program ','program_id=book_lesson_program.id','LEFT')
            ->join(' book_service_target ','service_target_id=book_service_target.id','LEFT')
            ->join(' book_lesson_nature ','lesson_nature_id=book_lesson_nature.id','LEFT')
            ->join(' book_user ','teacher_id=book_user.id','LEFT')
            ->join(' book_classroom ','classroom_id=book_classroom.id','LEFT')
            ->join(' book_city ','book_lesson.city_id=book_city.id','LEFT')
            ->field('book_lesson.id,book_lesson.lesson_sn,book_subject.subject,book_lesson_program.program,book_service_target.service_target,book_lesson_nature.lesson_nature,book_user.full_name,book_user.sex,book_user.age,book_classroom.classroom_address,book_lesson.lesson_method,book_lesson.is_comment,book_lesson.lesson_cost,book_lesson.teacher_group_description,book_lesson.lesson_feature,book_lesson.cost_type,book_lesson.add_description,book_lesson.teacher_description,book_lesson.classroom_description,book_lesson.lesson_name,book_lesson.adapt_crowd,book_lesson.cost_type_description,book_lesson.lesson_time_description,book_lesson.teacher_group_images,book_lesson.lesson_num,book_city.city')
            ->find();
        echo json_encode($lesson);

    }
    public function student_list(){  // lesson_code  lesson_num(当前课时数)
            $names=Db::name('order')->where('book_order.lesson_id="'.$_POST['id'].'" AND com.comment_rank<4')
                ->join('book_lesson_comment com','book_order.user_id=com.comment_id AND com.lesson_id="'.$_POST['id'].'"','LEFT')
                ->join('book_user us','book_order.user_id=us.id','LEFT')
                ->field('book_order.user_id,us.full_name,us.tel,us.sex')
                ->select();
            return json($names);
        }
    public function end_lesson(){
            $status0['status']=0;
            $info['is_approve']=2;
            $end=Db::name('lesson')
                ->where('id='.$_POST['id'])->update($info);
        if($end){
            return json($status0);
        }
    }
    //到课(学生出勤)情况处理
    public function attend_lesson(){
        $status0['status']=0;
        if(request()->isPost()){
            $id = $_POST['lesson_id'];
            $user_id = json_decode($_POST['user_id']);
            $info=Db::name('lesson')->where(array('id'=>$id))->find();
            $names=Db::name('lesson_comment')->where(array('lesson_id'=>$_POST['lesson_id']))->select();
            // 制作评论表里 当前课时数
            foreach($names as $k1=>$v1){
                $new_data['complete_lesson_num']=$names[$k1]['complete_lesson_num']+1;
                Db::name('lesson_comment')->where(array('lesson_id'=>$id))->update($new_data);
            }
            $lesson_data['com_lesson_num']=$new_data['complete_lesson_num'];
            Db::name('lesson')->where('id='.$id)->update($lesson_data);
            $order_name=Db::name('order')->where(array('lesson_id'=>$id))->select();
            //dump($order_name);die;
            // 制作Order表里的当前课时数
            foreach($order_name as $k2=>$v2){
                $ord['complete_lesson_num']=$names[$k2]['complete_lesson_num']+1;
                Db::name('order')->where(array('lesson_id'=>$id))->update($ord);
            }
            //制作Order表里逃课数
            if($info['cost_type'] == 1){
                $where['lesson_id'] = $_POST['lesson_id'];
                $where['comment_rank'] = array('elt',3);
                $comment_name = Db::name('lesson_comment')->where($where)->select();
                foreach($comment_name as $k3=>$v3){
                    $arr[]=$comment_name[$k3]['comment_id'];
                }
            }elseif($info['cost_type'] == 2){
                foreach($order_name as $k3=>$v3){
                    $arr[]=$order_name[$k3]['user_id'];
                }
            }
            $diff = array_diff($arr,$user_id);
            if($diff){
                foreach($diff as $k4=>$v4){
                    $escape=Db::name('order')->where(array('lesson_id'=>$id,'user_id'=>$v4))->find();

                    $escape['escape_lesson_num']=$escape['escape_lesson_num']+1;
                    Db::name('order')->where(array('lesson_id'=>$id,'user_id'=>$diff[$k4]))->update($escape);
                }
            }else{

            }
            // 制作 comment表的当前出席人数
            foreach($user_id as $k5=>$v5){
                $one_comment=Db::name('lesson_comment')->where(array('lesson_id'=>$id,'comment_id'=>$user_id[$k5]))->find();
                $data['attend_lesson_num']= $one_comment['attend_lesson_num']+1;
                //dump($attend_lesson_num);
                Db::name('lesson_comment')->where(array('lesson_id'=>$id,'comment_id'=>$v5))->update($data);
            }
            echo json_encode($status0);
        }

    }

    public function write_lesson_num_time($id){
        $info = Db::name('lesson')->where(array('id'=>$id))->field('book_lesson.lesson_num')->find();
        return json($info);
    }

    public function lesson_num_time($id){
        $lesson_num_time = Db::name('lesson_num_time');
        $res = $lesson_num_time->where('book_lesson_num_time.lesson_id=' .$id)
            //->join('book_lesson_comment','book_lesson_num_time.lesson_id=book_lesson_comment.lesson_id')
            ->select();
        $comment=Db::name('lesson_comment')->where('book_lesson_comment.lesson_id=' .$id)->find();
        foreach($res as $key => $val){
            $res[$key]['complete_lesson_num']=$comment['complete_lesson_num'];
        }
        return json($res);

    }
    public function write_time(){
        $status0['status']=0;
        $status1['status']=1;
        $status2['status']=2;
        $lesson_details_id=json_decode($_POST['lesson_id']);
        $lesson_number = json_decode($_POST['lesson_number']);
        $lesson_start_time = json_decode($_POST['lesson_start_time']);
        $lesson_end_time = json_decode($_POST['lesson_end_time']);
            $arr = ['lesson_id'=>$lesson_details_id,'lesson_number'=>$lesson_number,'lesson_start_time'=>$lesson_start_time,'lesson_end_time'=>$lesson_end_time];
            foreach($lesson_details_id as $key => $val){
                $data['lesson_id'] = $arr['lesson_id'][$key];
                $data['lesson_number'] = $arr['lesson_number'][$key];
                $data['lesson_start_time'] = strtotime($arr['lesson_start_time'][$key],time());
                $data['lesson_end_time'] = strtotime($arr['lesson_end_time'][$key],time());
                $lesson_num_time = Db::name('lesson_num_time');
                if($data['lesson_start_time'] || $data['lesson_end_time']){
                    $results = $lesson_num_time->data($data)->insert();
                    if($results){

                    }else{
                       // return json($status1);
                    }
                }else{
                   // return json($status2);
                }
            }
        echo json_encode($status0);
    }
    public function update_lesson_num_time($id)
    {   $lesson=Db::name('lesson')->where('id='.$id)->find();
        $lesson_num_time = Db::name('lesson_num_time');
        $res = $lesson_num_time->where('lesson_id=' .$id)->order('lesson_number asc')->select();
        foreach ($res as $k => $v) {
            $res[$k]['com_lesson_num'] = $lesson['com_lesson_num'];
        }
        return json($res);
    }
    public function edit_time(){
        $status0['status']=0;
        $status1['status']=1;
        $status2['status']=2;
        $lesson_number = json_decode($_POST['lesson_number']);
        $lesson_start_time = json_decode($_POST['lesson_start_time']);
        $lesson_end_time = json_decode($_POST['lesson_end_time']);
        $id = $_POST['lesson_id'];
        $lesson_num_time = Db::name('lesson_num_time');
        $res = $lesson_num_time->where('lesson_id=' .$id)->select();
        if(request()->isPost()){
            foreach($res as $key => $val){
                if(empty($lesson_start_time[$key]) || empty($lesson_end_time[$key])){
                    return json($status1);
                }else if(!empty($lesson_start_time[$key])){
                    $lesson_num_time = Db::name('lesson_num_time');
                    $data['lesson_number'] = $lesson_number[$key];
                    $data['lesson_start_time'] = strtotime($lesson_start_time[$key],time());
                    $data['lesson_end_time'] = strtotime($lesson_end_time[$key],time());
                    $result = $lesson_num_time->where('id='.$res[$key]['id'].' AND lesson_number='.$lesson_number[$key])->update($data);
                    if($result){
                        //echo json_encode($status0);
                    }else{
                        //echo json_encode($status2);
                    }
                }
            }
            echo json_encode($status0);
        }

    }
    public function class_type(){
        $info = Db::name('class')
            ->select();
        return json($info);
    }
    public function lesson(){
        $info = Db::name('lesson')
            ->select();
        return json($info);
    }
    public function lesson_program(){
        $id = input( 'subject_id' );
        $program =Db::name( 'lesson_program' );
        $programs = $program->where ( array ('subject_id' => $id ) )->select ();
        return json ( $programs );
    }
    public function lesson_aim(){
        $info = Db::name('lesson_aim')
            ->select();
        return json($info);
    }
    public function lesson_style(){
        $info = Db::name('lesson_style')
            ->select();
        return json($info);
    }
    public function all_classroom(){
        $info = Db::name('classroom')
            ->select();
        return json($info);
    }
    public function start_lesson(){
        $info = Db::name('start_lesson')
            ->select();
        return json($info);
    }
    public function grade(){
        $info = Db::name('grade')
            ->select();
        return json($info);
    }
    public function add_lesson(){
        $status0['status']=0;
        $status1['status']=1;
        if (request()->isPost()){//判断是否新增成功
            //dump(input("post."));die;
            $data=$_POST;
            $data['grade_id'] = substr(input("post.grade_id"),0,strlen(input("post.grade_id"))-1); ;//所接收的年级id
            $data['is_approve']=0;
            $data['registration_end_time']=strtotime(input("post.registration_end_time"));
            $te_info = Db::name('user')->where(array('id' => $data['teacher_id']))->find();//根据所接收的教师id获取教师电话，制作课程代号
            $tel = $te_info['tel'];
            $teacher_lesson = Db::name('lesson')->where(array('teacher_id'=>$data['teacher_id']))->select();
            if($teacher_lesson){
                foreach($teacher_lesson as $k => $v){
                    $arr[]=substr($teacher_lesson[$k]['lesson_sn'],0,4);
                }
                $data['lesson_sn'] = sprintf("%04d",max($arr)+1).$tel;

            }else{
                $data['lesson_sn'] = sprintf("%04d",1) . $tel;//制作的课程代码
            }
            $lesson_details = Db::name('lesson');
            if ($rec=$lesson_details->insertGetId($data)) {
                $status0['id']=$rec;
                $lesson_num = $_POST['lesson_num'];
                //dump($lesson_num);dump($rec);die;
                for($i=1;$i<=$lesson_num;$i++){
                    $info['lesson_id'] = $rec;
                    $info['lesson_number'] = $i;
                    $info['lesson_start_time'] = '0';
                    $info['lesson_end_time'] = '0';
                    $result[]= Db::table('book_lesson_num_time')->insertGetId($info);
                }

                if(count($result) == $lesson_num){
                    echo json_encode($status0);
                }

            } else {
                echo json_encode($status1);
            }

        }

    }
    //  教师端 确认当前课时结束
    public function end_lesson_now(){
        $status0['status']=0;
        $status1['status']=1;
        $status2['status']=2;
        if(request()->isPost()) {
            $lesson = Db::name('lesson')->where(array('id' => $_POST['lesson_id']))->find();
            if ($lesson['is_comment'] == 1) {
                $lesson_num = $lesson['lesson_num'];
                $comment = Db::name('lesson_comment')->where(array('lesson_id' => $_POST['lesson_id']))->select();
                if (!($lesson_num - $_POST['comment_lesson_number'] == 0 || $lesson_num - $_POST['comment_lesson_number'] == 1)) {
                    foreach ($comment as $k => $v) {
                            if ($_POST['comment_lesson_number'] !=$comment[$k]['attend_lesson_num']) {
                                    $comment[$k]['attend_lesson_num'] = $_POST['comment_lesson_number'];//将所接收的课时数替换order表中的attend_lesson_num的课时数
                                    Db::name('lesson_comment')->where(array('comment_id' => $comment[$k]['comment_id'], 'lesson_id' => $comment[$k]['lesson_id']))->update($comment[$k]);

                                if ($comment[$k]['comment_rank'] <= 3) {
                                    $comment[$k]['comment_status'] = 0;
                                    $comment[$k]['comment_lesson_number'] = $_POST['comment_lesson_number'];
                                    $comment[$k]['comment_start_time']=time();
                                    $rec = Db::name('lesson_comment')->where(array('comment_id' => $comment[$k]['comment_id'], 'lesson_id' => $comment[$k]['lesson_id']))->update($comment[$k]);

                                    if ($rec) {
                                        // echo '<script>alert(\'1，成功修改，偶数，改状态，改课时数\');</script>';
                                    } else {
                                        //echo '<script>alert(0);</script>';
                                    }
                                } else {

                                }
                            } else {
                                if ($comment[$k]['comment_rank'] <= 3) {
                                    $comment[$k]['comment_lesson_number'] = $_POST['comment_lesson_number'];
                                    $comment[$k]['comment_status'] = 0;
                                    $comment[$k]['attend_lesson_num'] = $_POST['comment_lesson_number'];
                                    $comment[$k]['comment_start_time']=time();
                                    Db::name('lesson_comment')->where(array('comment_id' => $comment[$k]['comment_id'], 'lesson_id' => $comment[$k]['lesson_id']))->update($comment[$k]);
                                } else {

                                }

                            }


                    }
                    return json($status0);
                } else { // 默认评价的

                    foreach ($comment as $k => $v) {
                            if ($_POST['comment_lesson_number'] !=$comment[$k]['attend_lesson_num']) {
                                    $comment[$k]['attend_lesson_num'] = $_POST['comment_lesson_number'];//将所接收的课时数替换order表中的attend_lesson_num的课时数

                                    Db::name('lesson_comment')->where(array('comment_id' => $comment[$k]['comment_id'], 'lesson_id' => $comment[$k]['lesson_id']))->update($comment[$k]);

                                if ($comment[$k]['comment_rank'] <= 3) {
                                    $comment[$k]['comment_lesson_number'] = $_POST['comment_lesson_number'];
                                    $comment[$k]['comment_start_time']=time();
                                    $rec = Db::name('lesson_comment')->where(array('comment_id' => $comment[$k]['comment_id'], 'lesson_id' => $comment[$k]['lesson_id']))->update($comment[$k]);

                                    if ($rec) {
                                        //echo '<script>alert(\'1，成功修改，偶数，改状态，改课时数\');</script>';
                                    } else {
                                        // echo '<script>alert(0);</script>';
                                    }
                                } else {

                                }
                            } else {
                                if ($comment[$k]['comment_rank'] <= 3) {
                                    $comment[$k]['comment_lesson_number'] = $_POST['comment_lesson_number'];
                                    $comment[$k]['comment_status'] = 1;
                                    $comment[$k]['attend_lesson_num'] = $_POST['comment_lesson_number'];
                                    Db::name('lesson_comment')->where(array('comment_id' => $comment[$k]['comment_id'], 'lesson_id' => $comment[$k]['lesson_id']))->update($comment[$k]);
                                } else {
                                }
                            }


                    }
                    return json($status0);
                    //echo '<script>alert(\'本课不发起评价\')</script>';
                }
            } else {  //不需要评论的
                $names_c = Db::name('lesson_comment')->where(array('lesson_id' => $_POST['lesson_id']))->select();

                //dump($names_c);die;
                foreach ($names_c as $k1 => $v1) {
                    $names_c[$k1]['comment_lesson_number'] = $_POST['comment_lesson_number'];
                    $n_c = Db::name('lesson_comment')->where(array('lesson_id' => $_POST['lesson_id'], 'comment_id' => $names_c[$k1]['comment_id']))->update($names_c[$k1]);
                }
                if ($n_c) {
                    return json($status0);
                    //echo  '<script>alert(1);</script>';
                } else {
                    return json($status1);
                    // echo  '<script>alert(\'no_c 失败\');</script>';
                }
            }
        }
        }

    //提现回显数据
    public function teacher_money(){
        $id=$_POST['id'];
        $teacher = Db::name('teacher')
            ->join('book_user','book_teacher.teacher_id=book_user.id')
            ->where('book_teacher.teacher_id='.$id)
            ->find();
        return json($teacher);
    }

    //教师申请提现
    public function apply_withdrawals(){
        $status0['status']=0;
        $status1['status']=1;
        $status2['status']=2;
        $status3['status']=3;
        $id=$_POST['id'];
        $teacher = Db::name('teacher')
            ->join('book_user','book_teacher.teacher_id=book_user.id')
            ->where('book_teacher.teacher_id='.$id)
            ->select();
        if(request()->isPost()) {
            $withdrawals = Db::name('teacher_withdrawals');
            $results = $withdrawals->where('tea_id="'.$id.'" AND teacher_withdrawals_status=0')->find();
            if (!empty($results)) {
                return json($status3);
                //echo '<script>alert(\'申请奖金提现失败，你还有申请的提现正在处理中！\');history.back(-1);</script>';
            } else {
                $user = Db::name('user');
                $tea = Db::name('teacher');
                $data_rec_bonus['rec_bonus'] = $teacher[0]['rec_bonus'] - $_POST['rec_bonus'];
                $data['teacher_bonus'] = $teacher[0]['teacher_bonus'] - $_POST['teacher_bonus'];
                if (($_POST['rec_bonus'] <= $teacher[0]['rec_bonus'] && $_POST['rec_bonus'] > 0) || ($_POST['teacher_bonus'] <= $teacher[0]['teacher_bonus'] && $_POST['teacher_bonus'] > 0)) {
                    if (empty($_POST['rec_bonus'])) {
                        $result = $tea->where('teacher_id=' . $id)->update($data);
                        if ($result) {
                            $tea_withdrawals = new TeacherWithdrawals();
                            $data['tea_id'] = $id;
                            $data['teacher_withdrawals_money'] = $_POST['teacher_bonus'];
                                if ($tea_withdrawals->data($data)->insert()) {
                                    $account = new Account();
                                    $datas['account_id'] = $teacher[0]['teacher_id'];
                                    $datas['bonus_record'] = -$_POST['teacher_bonus'];
                                    $datas['bonus_record_time'] = time();
                                        if ($account->data($datas)->insert()) {
                                            return json($status0);
                                        } else {
                                            // echo '<script>alert(\'录入教师奖金提现流水记录失败！\');history.back(-1);</script>';
                                        }

                                } else {
                                    // echo '<script>alert(\'插入数据到教师奖金申请提现列表失败！\');history.back(-1);</script>';
                                }


                            //echo '<script>alert(\'申请教师奖金提现成功！\');window.location.href=\''.U('Teacher/withdrawals').'\';</script>';
                        } else {
                            return json($status1);
                            // echo '<script>alert(\'申请教师奖金提现失败！\');history.back(-1);</script>';
                        }
                    } else if (empty($_POST['teacher_bonus'])) {
                        $res = $user->where('id=' . $teacher[0]['teacher_id'])->update($data_rec_bonus);
                        if ($res) {

                            $tea_withdrawals = new TeacherWithdrawals();
                            $data['tea_id'] = $id;
                            $data['teacher_withdrawals_money'] = $_POST['rec_bonus'];
                                if ($tea_withdrawals->data($data)->insert()) {
                                    $account =new Account();
                                    $datas['account_id'] = $teacher[0]['teacher_id'];
                                    $datas['bonus_record'] = -$_POST['rec_bonus'];
                                    $datas['bonus_record_time'] = time();
                                        if ($account->data($datas)->insert()) {
                                            return json($status0);
                                        } else {
                                            // echo '<script>alert(\'录入推荐奖金流水记录失败！\');history.back(-1);</script>';
                                        }

                                } else {
                                    // echo '<script>alert(\'插入数据到教师推荐奖金申请提现列表失败！\');history.back(-1);</script>';
                                }


                            // echo '<script>alert(\'申请推荐奖金提现成功！\');window.location.href=\''.U('Teacher/withdrawals').'\';</script>';
                        } else {
                            return json($status1);
                            // echo '<script>alert(\'申请推荐奖金提现失败！\');history.back(-1);</script>';
                        }
                    } else {
                        return json($status2);
                        // echo '<script>alert(\'申请提现失败！\');history.back(-1);</script>';
                    }
                } else {
                    return json($status2);
                    //echo '<script>alert(\'你提现的金额不正确！\');history.back(-1);</script>';
                }
            }
        }
    }

//教师停课
    public function add_stop_les(){
        $status0['status']=0;
        $status1['status']=1;
        if(request()->isPost()){
            $data['les_id']=input("post.les_id");
            $data['t_id']=input("post.t_id");
            $data['t_stop_content']=input("post.t_stop_content");
            //dump($create);die;
                Db::name('teacher_stop_lesson')->insert($data);

            $info=Db::name('order')->where(array('lesson_id'=>input("post.les_id")))->select();

            if($info){
                return json($status0);
                //echo '<script>alert(\'发布成功！\');window.location.href=\''.U('Lesson/teacher_stop_lesson').'\';</script>';
            }else{
                return json($status1);
               // Db::name('order')->getError();
            }

        }
    }


    // 教师选学生停课
    public function add_stu_stop_les(){
        $status0['status']=0;
        $status1['status']=1;
        if(request()->isPost()){
                $data['stu_stop_id'] = $_POST['student_id'];
                $data['les_id'] = $_POST['les_id'];
                $data['t_id'] =$_POST['teacher_id'];
                $data['t_stop_content'] = $_POST['t_stop_content'];
                $rec=Db::name('teacher_stop_lesson')->insert($data);
            if($rec){
                return json($status0);
                //echo '<script>alert(\'发布成功！\');window.location.href=\''.U('Lesson/teacher_stop_lesson').'\';</script>';
            }else{
                return json($status1);
               // echo '<script>alert(\'发布失败\');history.back(-1);</script>';
            }

        }
    }
}